<?xml version="1.0" encoding="UTF-8" ?>

<!-- One XSLT that use HTML + CSS to display all the relevant information about a player -->

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

	<xsl:output method="xml" indent="yes"/>
	
	<xsl:template match="/">
	
	<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="xslt/player_page.xslt"</xsl:processing-instruction>
	
	<players>
		<xsl:for-each select="/league/players/player">
			<xsl:variable name="playerId" select="@id"/>
			<player>
	
		<id><xsl:value-of select="@id" /></id>
		<name><xsl:value-of select="playerName" /></name>
		<nationality><xsl:value-of select="nationality" /></nationality>
		<height><xsl:value-of select="height" /></height>
		<weight><xsl:value-of select="weight" /></weight>
		<nickname><xsl:value-of select="nickname" /></nickname>
		<bday><xsl:value-of select="bday" /></bday>
		<position><xsl:value-of select="@position" /></position>

		<xsl:apply-templates select="awards" />

		<xsl:apply-templates select="/league/teams/team[./squad/squad_player[@playerId = $playerId]]">
			<xsl:with-param name="player" select="@id"></xsl:with-param>
		</xsl:apply-templates>
		
		<yellowCards>
			<xsl:value-of select="count(/league/fixtures/game/discipline/card[@playerId = $playerId and @type = 'yellow'])" />
		</yellowCards>
		<redCards>
			<xsl:value-of select="count(/league/fixtures/game/discipline/card[@playerId = $playerId and @type = 'red'])" />
		</redCards>



		<goalsScored>
			<xsl:attribute name="total" select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId])" />
			<freePlay>			<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Free_Play' ])"/></freePlay>
			<freeKick>			<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Free_Kick' ])"/></freeKick>
			<counterAttack>	<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Counter_Attack' ])"/></counterAttack>
			<inPlayCross>		<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='In_Play_Cross' ])"/></inPlayCross>
			<setPiece>			<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Set_Piece' ])"/></setPiece>
			<ownGoal	>			<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Own_Goal' ])"/></ownGoal>
			<longShot>			<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Long_Shot' ])"/></longShot>
			<penalty>				<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Penalty' ])"/></penalty>
			<pressing>			<xsl:value-of select="count(/league/fixtures/game/score/goals/goal[@playerId = $playerId]/goalevent[@event='Pressing' ])"/></pressing>
		</goalsScored>
	</player>
	</xsl:for-each>
	
	</players>
	</xsl:template>

	<xsl:template match="awards">
		<xsl:copy-of select="."/>
	</xsl:template>


	<xsl:template match="team">
		<xsl:param name="player" />
		<team_info>
			<id><xsl:value-of select="@id" /></id>
			<name><xsl:value-of select="teamName" /></name>
			<playerNumber><xsl:value-of select="./squad/squad_player[@playerId = $player]/number" /></playerNumber>
		</team_info>		
	</xsl:template>



</xsl:stylesheet>
